<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Input;
use Zizaco\Entrust\Traits\EntrustUserTrait;

class User extends Authenticatable
{
    use EntrustUserTrait;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function scopeName($query, $name = '')
    {
        $name = $name != '' ? : Input::get('name', '');
        if (!empty($name)) {
            return $query->where('name', 'like', "%{$name}%");
        }
        return $query;
    }

    public function scopeEmail($query, $email = '')
    {
        $email = $email != '' ? : Input::get('email', '');
        if (!empty($email)) {
            $query->where('email', 'like', "%{$email}%");
        }
        return $query;
    }

    public function roles()
    {
        return $this->belongsToMany('App\Models\Role');
    }
}
